SET(TARGET_NAME LibCommon)
#PROJECT(${TARGET_NAME})
#必须要有的宏定义
ADD_DEFINITIONS (-DLIB_COMMON_EXPORT)

IF (WIN32 )
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
    ADD_DEFINITIONS (-D_CRT_SECURE_NO_WARNINGS)
endif()
# ADD_DEFINITIONS (-DUSE_QT_BASIC)

	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/${TARGET_NAME})
	INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/LibVrpn)
	LINK_DIRECTORIES( ${PROJECT_BINARY_DIR}/lib)
	

    INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})
    LINK_DIRECTORIES(${QT_LIB_DIR})
	
    # INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR})
    # LINK_DIRECTORIES(${OSG_LIB_DIR})

    # INCLUDE_DIRECTORIES(${SPDLOG_INCLUDE_DIR})
    # LINK_DIRECTORIES(${SPDLOG_LIB_DIR})
#库文件在debug下名字后面加d
SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
#ADD_DEFINITIONS (${Qt5Widgets_DEFINITIONS})

FILE(GLOB_RECURSE ThisTarget_INCLUDE_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.h")
FILE(GLOB_RECURSE ThisTarget_SRC_LIST "${PROJECT_SOURCE_DIR}/${TARGET_NAME}/*.cpp")

source_group("include" FILES ${ThisTarget_INCLUDE_LIST})
source_group("src" FILES ${ThisTarget_SRC_LIST})

#ADD_EXECUTABLE(${TARGET_NAME} ${ThisTarget_SRC_LIST} ${ThisTarget_INCLUDE_LIST} )
ADD_LIBRARY(${TARGET_NAME} SHARED ${ThisTarget_SRC_LIST} ${ThisTarget_INCLUDE_LIST})

SET(ADDITIONAL_LIBRARIES_RELEASE
     # Qt5Core
     # Qt5Network
     # osg
)

SET(ADDITIONAL_LIBRARIES_DEBUG
     # Qt5Cored
     # Qt5Networkd
     # osgd
)


TARGET_LINK_LIBRARIES(${TARGET_NAME} PRIVATE debug "${ADDITIONAL_LIBRARIES_DEBUG}" PRIVATE optimized "${ADDITIONAL_LIBRARIES_RELEASE}")
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin)
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin)

#set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE /ENTRY:mainCRTStartup")# WINDOWS

set_target_properties(${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib)
set_target_properties(${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib)

#=============Copy Plugins Runtime FILES to Main Project============ 
#一般将此内容放在lib子项目的CMakelists.txt的最后，该方法采用POST_BUILD，
#所以需注意要复制的源应该是一个固定字符串，
#而不能用FILE GLOB的方法，因为在编译前该源为空，在VS中会出现MSB3073错误，提示copy from 为空值。

SET(DLL_FILE_DEBUG
    ${PROJECT_BINARY_DIR}/bin/${TARGET_NAME}d.dll 
) 

SET(DLL_FILE_RELEASE 
    ${PROJECT_BINARY_DIR}/bin/${TARGET_NAME}.dll 
) 

#copy LibCommon to the unreal project
# add_custom_command(TARGET ${TARGET_NAME} 
   # POST_BUILD 
   # COMMAND ${CMAKE_COMMAND} -E 
       # copy_if_different  
       # "$<$<CONFIG:Release>:${DLL_FILE_RELEASE}>"  
       # "$<$<CONFIG:Debug>:${DLL_FILE_DEBUG}>"  
       # "${PROJECT_SOURCE_DIR}/UEPlugin/Binaries/Win64/" 
# ) 
